<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>商家管理平台-用户登录</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!--引入Bootstrap-->
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
    <script src="js/jquery.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <!--自定义工具-->
    <script src="js/HttpUtil.js"></script>
    <!--导入vue 包-->
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>

    <!--参数校验工具-->
    <script src="validation-1.19.2/jquery.validate.min.js"></script>
    <script src="validation-1.19.2/localization/messages_zh.min.js"></script>
</head>
<body>
<div class="container-fluid" style="margin-top: 1%">
    <!-- 头信息 -->
    <header>
        <div class="col-xs-offset-1">
            <img src="../shop/images/logo.png">
        </div>
        <hr>
        <div class="row" style="background-color: #A4D3EE">
            <div class="col-xs-3 col-lg-offset-1">
                <h3>欢迎登入GitBug商城管理系统</h3>
            </div>
        </div>
    </header>


</div>
<div class="container-fluid">
    <div class="row col-lg-offset-3 col-md-5"  style="margin-top: 10%">
            <div class="panel-body">
                <form class="form-horizontal" id="form_login">
                    <div class="form-group">
                        <label for="userName" class="col-sm-2 control-label">用户名</label>
                        <div class="col-sm-10">
                            <input type="text" name="userName" class="form-control" id="userName" placeholder="用户名">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="password" class="col-sm-2 control-label">密码</label>
                        <div class="col-sm-10">
                            <input type="password" name="password" class="form-control" id="password" placeholder="密码">
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-10">
                            <button type="button" onclick="formSubmit()" class="btn btn-default">登录</button>
                        </div>
                    </div>
                </form>
            </div>
    </div>
</div>
</body>
</html>
<script>
    $(function () {
        init();
    });

    function init() {
        //加载参数校验工具
        $("#form_login").validate(
            {
                rules: {
                    userName: {required: true},
                    password: {required: true, digits: true}
                },
                messages: {
                    userName: {
                        required: "用户不能为空！",
                    },
                    password:{
                        required:"密码不能为空",
                        digits: "密码为数字",
                    }
                }
            }
        );
    }

    function formSubmit() {
        //获取验证框架结果
        let validateResult = $("#form_login").valid();
        if (!validateResult) {
            //校验不通过
            return;
        }

        //获取表单数据
        let userNameValue = $("#userName").val();
        let passwordValue = $("#password").val();

        //发起http 请求
        let url = "/SellerLogin";
        let params = {userName: userNameValue, password: passwordValue};
        postWithJson(url, params, function (data) {
            //清除上次登入
            localStorage.removeItem("seller")
            //登录成功，保存商家信息到浏览器的存储区域
            localStorage.setItem("seller", JSON.stringify(data))
            //跳转页面
            location.href="home_admin.html"
        })
    }
</script>
